package com.sgb.kjwl.view.ui.adapter.manage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemEcommendedEnterprisesBinding;
import com.sgb.kjwl.interfaces.RecyclerClick;
import com.sgb.kjwl.model.entity.manage.TheEnterpriseOfEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MLog;

import java.util.List;

/***
 * 企业经营-推荐企业-最新入驻
 */
public class RecommendedEnterprisesAdapter extends BaseRecycleAdapter<TheEnterpriseOfEntity> {
    private static final String TAG = "RecommendedEnterprisesAdapter";
    private RecyclerClick<TheEnterpriseOfEntity> mRecyclerClick;
    private boolean isHide = false;

    public void setmRecyclerClick(RecyclerClick<TheEnterpriseOfEntity> mRecyclerClick) {
        this.mRecyclerClick = mRecyclerClick;
    }

    public RecommendedEnterprisesAdapter(Context context, List<TheEnterpriseOfEntity> datas) {
        super(context, R.layout.item_ecommended_enterprises, datas);
    }

    public RecommendedEnterprisesAdapter(Context context, List<TheEnterpriseOfEntity> datas, boolean isHide) {
        super(context, R.layout.item_ecommended_enterprises, datas);
        this.isHide = isHide;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, final TheEnterpriseOfEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemEcommendedEnterprisesBinding binding = (ItemEcommendedEnterprisesBinding) holder.getmBinding();
        if (entity == null) {
            MLog.d(TAG, "RecommendedEnterprisesAdapter entity is null");
            return;
        }
        binding.tvLine.setVisibility(View.VISIBLE);
        if (entity.getStaffNumber() == null || entity.getStaffNumber().equals("")) {
            binding.tvLine.setVisibility(View.GONE);
            binding.tvCount.setVisibility(View.GONE);
        } else {
            binding.tvCount.setText(entity.getStaffNumber() + "人");
            binding.tvCount.setVisibility(View.VISIBLE);
        }
        if (entity.getServiceType() == null || entity.getServiceType().equals("")) {
            binding.tvLine.setVisibility(View.GONE);
            binding.tvServiceType.setVisibility(View.GONE);
        } else {
            binding.tvServiceType.setText(entity.getServiceType());
            binding.tvServiceType.setVisibility(View.VISIBLE);
        }

        if (entity.getLatitude()!=null&&entity.getLongitude()!=null&&entity.getLatitude().equals("0") && entity.getLongitude().equals("0")) {//经纬度为0
            if (entity.getAddressNew() != null && !entity.getAddressNew().equals("")) {//地址不为空
                binding.tvAddress.setVisibility(View.VISIBLE);
            } else {
                binding.tvAddress.setVisibility(View.GONE);
            }
            binding.tvDistance.setVisibility(View.GONE);
        } else {
            if (entity.getAddressNew() != null && !entity.getAddressNew().equals("")) {//地址不为空
                binding.tvAddress.setVisibility(View.VISIBLE);
                binding.tvDistance.setVisibility(View.VISIBLE);
            } else {
                binding.tvAddress.setVisibility(View.GONE);
                binding.tvDistance.setVisibility(View.GONE);
            }
        }

        if (isHide){
            binding.tvFollow.setVisibility(View.GONE);
            binding.tvDistance.setVisibility(View.GONE);
        }
        binding.tvFollow.setSelected(entity.getFollow());
        TextView tv = holder.getItem().findViewById(R.id.tv_follow);
        tv.setOnClickListener(v -> {
            if (mRecyclerClick != null){
                mRecyclerClick.followClick(entity);
            }
        });
    }


}
